//
//  FeedbackViewModel.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/1/22.
//

import Foundation
import LeanCloud

class FeedbackViewModel : NotifyBaseModel {
    @Published var isSuc :Bool  = false
    
    //按正常逻辑需要先上传图片视频，才能提交数据，但是目前还没有这个功能
    func publish(title:String,content:String) {
        request(isLoading: true) {
            try check(!title.isEmpty, "标题不能为空")
            try check(!content.isEmpty, "内容不能为空")
            let bean = MsgBean()
            bean.statusTitle = "意见反馈"
            bean.title = title
            bean.content = content
            bean.isHot = false
            bean.userId = userManager.isLogin() ? userManager.getUserId() : getDeviceId()
            bean.userName =  userManager.getName()
            try await LeancloudManager.instance.save(todo: bean)
        } suc: {
            self.isSuc = true
            showToast("提交成功")
        } fail: {
            showToast($0.message)
        }
    }
    
}
